package leetcode.oldVersion;

import java.util.HashSet;

public class lc128 {
    public int solve(int[] nums) {
        if (nums == null || nums.length == 0) return 0;
        HashSet<Integer> set = new HashSet<>();
        int maxLen = 0;

        for (int num : nums) {
            set.add(num);
        }
        for (int num : set) {
            int pre = num-1;
            if (set.contains(pre)) {//璇存槑褰撳墠num涓嶆槸鏁板垪鐨勮捣鐐癸紝璺宠繃鎿嶄綔

            }else {//num涓哄綋鍓嶆暟鍒楃殑璧风偣锛屽鎵捐鏁板垪鑳藉惁缁х画鎵╁睍
                int curNum = num;
                int curLen=1;
                while (set.contains(curNum+1)) {
                    curNum++;
                    curLen++;
                }
                maxLen=Math.max(maxLen,curLen);
            }
        }
        return maxLen;
    }
    public static void main(String[] args) {
        int[] nums1 = {1,2,3,5};
        lc128 solution = new lc128();
        System.out.println(solution.solve(nums1));

        int[] nums2 = {100,4,200,1,3,2};
        System.out.println(solution.solve(nums2));

        int[] nums3 = {0,3,7,2,5,8,4,6,0,1};
        System.out.println(solution.solve(nums3));

        int[] nums4 = {1,0,1,2};
        System.out.println(solution.solve(nums4));
    }
}
